package com.ijunfu.spring.conditional._03_conditional_condition.condition;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;

/**
 *
 * @Title  : 
 * @Author : ijunfu <ijunfu@163.com>
 * @Date   : 2023/11/6 12:03
 * @Version: 1.0
 * @Motto  : 世界很大 世界很小
 *
 */
@Slf4j
public class MyH2DatabaseCondition implements Condition {
    @Override
    public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
        Boolean flag = Boolean.FALSE;

        // 是否存在H2 database驱动
       try {
           context.getClassLoader().loadClass("org.h2.Driver");
           flag = Boolean.TRUE;
       } catch (Exception ex) {
           log.error("load h2Database driver fail: {}",ex.getMessage(), ex);
       }

        return flag;
    }
}
